`ifndef APB_SLV_MONITOR_SV
`define APB_SLV_MONITOR_SV


class apb_slv_monitor extends uvm_monitor;

	virtual apb_interface 								vif;
	uvm_analysis_port #(apb_transaction) 	ap;

	`uvm_component_utils(apb_slv_monitor)

	function new(string name = "apb_slv_monitor", uvm_component parent = null);
		super.new(name, parent);
	endfunction : new

	function void build_phase(uvm_phase phase);
		super.build_phase(phase);

		ap = new("ap", this);
		if(!uvm_config_db #(virtual apb_interface)::get(this, "", "vif", vif))
			`uvm_fatal("GETCFG", "cannot get vif from config DB!")
	endfunction : build_phase

	function void connect_phase(uvm_phase phase);
		super.connect_phase(phase);
	endfunction : connect_phase

	task main_phase(uvm_phase phase);
		apb_transaction tr;

		while(1) begin
			@(vif.cb_mon);
			if(vif.cb_mon.PENABLE && vif.cb_mon.PSEL && vif.cb_mon.PREADY && vif.cb_mon.PRESETn) begin
				tr = apb_transaction::type_id::create("tr");
				tr.addr 		= vif.cb_mon.PADDR;
				tr.wdata 		= vif.cb_mon.PWDATA;
				tr.rdata 		= vif.cb_mon.PRDATA;
				tr.penable  = vif.cb_mon.PENABLE;
				tr.psel			= vif.cb_mon.PSEL;
				tr.pwrite   = vif.cb_mon.PWRITE;
				tr.pslverr 	= vif.cb_mon.PSLVERR;
				tr.pprot		= vif.cb_mon.PPROT;
				tr.pstrb		= vif.cb_mon.PSTRB;
				ap.write(tr);
			end
		end
	endtask : main_phase

endclass : apb_slv_monitor


`endif // APB_SLV_MONITOR_SV
